//
//  BoatInfoCell.m
//  WOFishingBoat
//
//  Created by 郑逸凯 on 2018/12/18.
//  Copyright © 2018年 郑逸凯. All rights reserved.
//

#import "BoatInfoCell.h"
#import <Masonry/Masonry.h>
#import "UIImageView+WoWebCache.h"
#import "PhotoModel.h"

@interface BoatInfoCell ()
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UILabel *statusLabel;
@property (nonatomic,strong)UILabel *timeLabel;
@property (nonatomic,strong)UIView *separateView;
@property (nonatomic,strong)UIImageView *imageIcon;

@end

@implementation BoatInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupSubviews];
        [self performLayout];
    }
    return self;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


#pragma mark - Life Cycle
#pragma mark - Public Methods

- (void)reloadCell:(BoatInfoModel *)model {
    self.titleLabel.text = model.name;
    NSString *message =@"离线";
    if (model.status == 1) {
        message = @"空闲中";
    }else if (model.status == 2) {
        message = @"安全监控中...";
    }
    self.statusLabel.text = message;
//    self.timeLabel.text = @"2019/01/04 10:30:10";
    [self.imageIcon wo_setImageWithURL:[PhotoModel originalPathWiththumbnailPath:model.imgUrl]];
}

#pragma mark - Responder Actions
#pragma mark - Delegates
#pragma mark - Private Methods
- (void)setupSubviews {
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.imageIcon];
    [self.contentView addSubview:self.separateView];
    [self.imageIcon addSubview:self.statusLabel];
    [self.imageIcon addSubview:self.timeLabel];
}

- (void)performLayout {
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageIcon.mas_bottom).with.offset(SCREEN_SCALE_VALUE_IN_4_7(5));
        make.left.mas_equalTo(SCREEN_SCALE_VALUE_IN_4_7(20));
        make.height.mas_equalTo(SCREEN_SCALE_VALUE_IN_4_7(36));
        make.right.equalTo(self.contentView).with.offset(SCREEN_SCALE_VALUE_IN_4_7(-20));
    }];
    
    [self.imageIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(SCREEN_SCALE_VALUE_IN_4_7(15));
        make.left.mas_equalTo(SCREEN_SCALE_VALUE_IN_4_7(20));
        make.right.equalTo(self.contentView).with.offset(SCREEN_SCALE_VALUE_IN_4_7(-20));
        make.bottom.equalTo(self.contentView).with.offset(SCREEN_SCALE_VALUE_IN_4_7(-52));
    }];
    
    [self.separateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.equalTo(self.contentView).with.offset(-20);
        make.height.mas_equalTo(1);
        make.bottom.equalTo(self.contentView);
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.imageIcon);
        make.left.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(102, 20));
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.imageIcon);
        make.right.equalTo(self.imageIcon).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(150, 20));
    }];
   
}

#pragma mark - Setters and Getters

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = RGB16(0x333333);
        _titleLabel.font = [UIFont boldSystemFontOfSize:18];
    }
    return _titleLabel;
}


- (UIImageView *)imageIcon {
    if (!_imageIcon) {
        _imageIcon = [[UIImageView alloc] init];
        _imageIcon.layer.masksToBounds = YES;
        _imageIcon.layer.cornerRadius = 10;
    }
    return _imageIcon;
}

- (UIView *)separateView {
    if (!_separateView) {
        _separateView = [[UIView alloc] init];
        _separateView.backgroundColor = RGB16(0xE6E6E6);
    }
    return _separateView;
}

- (UILabel *)statusLabel {
    if (!_statusLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:14];
        _statusLabel = label;
    }
    return _statusLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:12];
        label.textAlignment = NSTextAlignmentRight;
        _timeLabel = label;
        
    }
    return _timeLabel;
}

#pragma mark - Helper
@end
